$(function () {
    getFollowWay();
    initScore();
    var followSource = $('#followSource').val();
    if(followSource == 6){
        var getPhone = transTelNumber($('#personPhone').val());
        $('#userPhone').text(getPhone);
    }else{
        var getPhone = transTelNumber($('#phone').val());
        $('#userPhone').text(getPhone);
    }

    var callTime = (clueFollowData.communicationTime / 60).toFixed(2);
    $('#communicationTime').html(callTime + ' 分钟');

    // 获取跟进录音文件路径
    getAudioUrl();
});

/**
 * 功能：获取录音文件路径并反显
 * 接口：任少熔
 * */
function getAudioUrl() {
    $.ajax({
        url: '/clueFollow/getCallRecord',
        type: 'POST',
        dataType: "json",
        data: {
            followId: clueFollowData.clueFollowId
        },
        success: (function (data) {
            if (data.code == "000000") {
                $('#audioUrl').prop('src', data.data);
            } else {
                $.alert('获取录音文件失败！');
            }
        }),
        error: (function () {
            $.alert('获取录音文件出错！');
        })
    })
}


// 获取跟进方式显示值
function getFollowWay() {
    var followWayType = $("#followWayType").val();
    var followWay = '';
    if (followWayType == 1) {
        followWay = "线上跟进"
    } else if (followWayType == 2) {
        followWay = "拜访"
    } else if (followWayType == 3) {
        followWay = "微信"
    } else if (followWayType == 4) {
        followWay = "线下电话"
    } else if (followWayType == 5) {
        followWay = "邮箱"
    } else if (followWayType == 6) {
        followWay = "陪访";
    }
    $('#followMethid').text(followWay);
}

function mySwiper() {
    var pageNumber;
    new Swiper('.swiper-container', {
        observer:true,
        observeParents: true,
        spaceBetween: 30,
        effect: 'fade',
        loop: true,
        // autoplay: true,
        delay: 300,
        pagination: {
            el: '.swiper-pagination',
            clickable: true,
        },
        navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
        },
        on: {
            slideChangeTransitionStart: function () {
                var index = Number(this.activeIndex);
                console.log(index);
                if (index == 4) {
                    index = 1
                }
                if (index == 0) {
                    index = 3;
                }
                pageNumber = index;
            }
        },
    });
}

function viewBtn(){
    mySwiper();
    $('#lookPhone').modal('show');


}


// 评分插件
function initScore() {
    jQuery(".js-raty").each(function () {
        var a = jQuery(this);
        a.raty({
            starType: "i",
            targetText: a.data("target-text") ? a.data("target-text") : '',
            score: a.data("score") ? a.data("score") : 0,
            number: a.data("number") ? a.data("number") : 5,
            cancel: a.data("cancel") ? a.data("cancel") : !1,
            target: a.data("target") ? a.data("target") : !1,
            targetScore: a.data("target-score") ? a.data("target-score") : !1,
            precision: a.data("precision") ? a.data("precision") : !1,
            cancelOff: a.data("cancel-off") ? a.data("cancel-off") : "mdi mdi-close fa-1-5x text-danger",
            cancelOn: a.data("cancel-on") ? a.data("cancel-on") : "mdi mdi-close fa-1-5x",
            starHalf: a.data("star-half") ? a.data("star-half") : "mdi mdi-star-half fa-1-5x text-warning",
            starOff: a.data("star-off") ? a.data("star-off") : "mdi mdi-star fa-1-5x text-gray",
            starOn: a.data("star-on") ? a.data("star-on") : "mdi mdi-star fa-1-5x text-warning",
            readOnly: true,
            // click: function (score, e) {
            // }
        })
    })
}

function editBtn(){
    $('#editFoloowTextarea').css('display','block');
    $('#followDetail').css('display','none');
    $('#edit').css('display','none');
    $('#sumberBtn').css('display','block');
    $('#editFoloowTextarea').val($('#followDetail').text());
}


function saveFollowDetail() {
    $.ajax({
        type:"post",
        url:"/clueFollow/updateClueFollow",
        contentType: "application/json;charset=utf-8",
        data:JSON.stringify({
            clueFollowId: $('#clueFollowId').val(),       // 跟进id
            followDetail: $.trim($('#editFoloowTextarea').val()), // 跟进详情
        }),
        dataType: 'json',
        async:false,
        success:function (data,status) {
            if(data.code == '000000'){
                $.alert("保存成功！");
                $('#followDetail').text($('#editFoloowTextarea').val());
                $('#edit').css('display','block');
                $('#sumberBtn').css('display','none');
                $('#editFoloowTextarea').css('display','none');
                $('#followDetail').css('display','block');
            }else{
                console.log('失败')
            }
        },
        error: (function (res) {
            $.alert("保存失败");
        })
    })
}
